package base.IO流;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class 排序字符文本_2 {
    public static void main(String[] args) throws IOException {
        /*1.读取数据*/
        File scr = new File(".\\src\\base\\IO流\\a.txt");
        FileReader fr = new FileReader(scr);
        StringBuilder sbu = new StringBuilder();
        int i;
        while((i = fr.read()) != -1){
            sbu.append((char) i);
        }
        String str = sbu.toString();
        Pattern p = Pattern.compile("\\d+(?:-\\d+)+");
        Matcher m = p.matcher(str);
        String s = null;
        while(m.find()){
            s = m.group();
        }
        System.out.println(s);

        /*2.排序*/
        Integer[] array = Arrays.stream(s.split("-"))//字符数组
                .map(Integer::parseInt) //int数组
                .sorted()
                .toArray(Integer[]::new);

        /*3.写出*/
        String outstr = Arrays.toString(array).replace(", ","-");
        String result = outstr.substring(1,outstr.length()-1);
        System.out.println(result);

    }
}
